package com.web.controller;

import com.core.dto.AccountDTO;
import com.service.user.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created with IntelliJ IDEA.
 * User: lxf
 * Date: 2017/1/4
 * Time: 14:40
 * To change this template use Editor | File and Code Templates.
 */
@Controller
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @RequestMapping("transfer/{sourceId}/{targetId}/{amount}")
    public String transferAccount(@PathVariable String sourceId, @PathVariable String targetId, @PathVariable String amount) {
        accountService.transferToAccount(sourceId, targetId, amount);
        System.out.println("transfer success");
        return "test";
    }

    @RequestMapping(value = "addAccount")
    public String addAccount(AccountDTO accountDTO) {
        accountService.saveAccount(accountDTO);
        return "test";
    }

    @RequestMapping(value = "find/{accountGuid}")
    public String findAccountById(@PathVariable String accountGuid, Model model) {
        AccountDTO accountDTO = accountService.findAccountByGuid(accountGuid);
        model.addAttribute("accountDTO", accountDTO);
        return "test";
    }

}
